/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef SWANLINK_FINANCE_MAKECARD_INTERFACES_INNERKITS_NATIVE_INCLUDE_MAKECARD_SRV_CLIENT_H
#define SWANLINK_FINANCE_MAKECARD_INTERFACES_INNERKITS_NATIVE_INCLUDE_MAKECARD_SRV_CLIENT_H

#include <singleton.h>
#include <memory>
#include <mutex>
#include "iremote_object.h"
#include "imakecard_srv.h"
#include "cashdevice_client.h"
namespace SwanLink {
namespace Finance {
class MakecardSrvClient final : public DelayedRefSingleton<MakecardSrvClient>, public CashDeviceClient {
    DECLARE_DELAYED_REF_SINGLETON(MakecardSrvClient)

 public:
    DISALLOW_COPY_AND_MOVE(MakecardSrvClient);


    /**
     * 设置打印机配置
     */
    int SetConfig(int handle, int configType, int configValue);
    /**
     * 设置standby参数
     */
    int SetStandbyParam(int handle, int dir, int pos, int standbyTime);
    /**
     * 打印卡片
     */
    int PrintCard(int handle, BmpInfo cardBmpInfo);
    /**
     * 获取打印机信息
     */
    int GetDeviceInfo(int handle, int infoType, char *infoValue);
    /**
     * 获取错误信息
     */
    int GetErrorString(int handle, int status, char* statusDesc);
    /**
     * 传动卡片到指定位置
     */
    int MoveCard(int handle, int postionMoveTo);
    /**
     * 翻转卡片
     */
    int FlipCard(int handle);

 protected:
    sptr<ICashDeviceSrv> Proxy() {return proxy_;}
    ErrCode Connect();

 private:
    class MakecardSrvDeathRecipient : public IRemoteObject::DeathRecipient {
     public:
        MakecardSrvDeathRecipient() = default;
        ~MakecardSrvDeathRecipient() = default;
        void OnRemoteDied(const wptr<IRemoteObject>& remote);

     private:
        DISALLOW_COPY_AND_MOVE(MakecardSrvDeathRecipient);
    };

    sptr<IMakecardSrv> proxy_ {nullptr};
    sptr<IRemoteObject::DeathRecipient> deathRecipient_ {nullptr};
    void ResetProxy(const wptr<IRemoteObject>& remote);
    std::mutex mutex_;
};
}  // namespace Finance
}  // namespace SwanLink

#endif  // SWANLINK_FINANCE_MAKECARD_INTERFACES_INNERKITS_NATIVE_INCLUDE_MAKECARD_SRV_CLIENT_H
